﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.scene3D.player.type.*;
    import mortal.game.view.common.*;

    public class PlayerModelConfig extends Object
    {
        private var _map:Dictionary;
        private var _modelShowMap:Dictionary;
        private var _modelShowMapById:Dictionary;
        private const connect:String = "_";
        private static var _instance:PlayerModelConfig;

        public function PlayerModelConfig()
        {
            this._map = new Dictionary();
            this._modelShowMap = new Dictionary();
            this._modelShowMapById = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" ResConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TPlayerModel = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TPlayerModel();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._map[_loc_2.type + this.connect + _loc_2.code + this.connect + _loc_2.sex + this.connect + _loc_2.career] = _loc_2;
            }
            return;
        }// end function

        private function writeModelShow(param1:Object) : void
        {
            var _loc_2:TModelShow = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TModelShow();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                if (this._modelShowMap[_loc_2.group] == null)
                {
                    this._modelShowMap[_loc_2.group] = new Array();
                }
                (this._modelShowMap[_loc_2.group] as Array).push(_loc_2);
                this._modelShowMapById[_loc_2.id] = _loc_2;
            }
            return;
        }// end function

        public function getModelShowById(param1:int) : TModelShow
        {
            return this._modelShowMapById[param1] as TModelShow;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_player_model.json");
            this.write(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_model_show.json");
            this.writeModelShow(_loc_1);
            return;
        }// end function

        public function getModelShowInfo(param1:int, param2:int, param3:int) : TModelShow
        {
            var _loc_4:TModelShow = null;
            var _loc_6:TModelShow = null;
            var _loc_5:* = this._modelShowMap[param1];
            if (_loc_5)
            {
                for each (_loc_6 in _loc_5)
                {
                    
                    if ((_loc_6.career == 0 || _loc_6.career == param3) && (_loc_6.sex == -1 || _loc_6.sex == param2))
                    {
                        _loc_4 = _loc_6;
                        break;
                    }
                }
            }
            return _loc_4;
        }// end function

        public function getModelInfo(param1:int, param2:int, param3:int, param4:int) : TPlayerModel
        {
            return this._map[param1 + this.connect + param2 + this.connect + param3 + this.connect + param4];
        }// end function

        public function getClothesModel(param1:int, param2:int, param3:int) : TPlayerModel
        {
            return this.getModelInfo(ModelType.CLOTHES, param1, param2, param3);
        }// end function

        public static function get instance() : PlayerModelConfig
        {
            if (_instance == null)
            {
                _instance = new PlayerModelConfig;
            }
            return _instance;
        }// end function

    }
}
